﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UserGUI : MonoBehaviour {
    IUserAction action;

    void Start() {
        action = SSDirector.getInstance().currentSceneController as IUserAction;
    }
    void Update() {
        if (action.CheckGameState() != 0) {
            return;
        }
        if (Input.GetMouseButtonUp(0)) {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit)) {
                string name = hit.transform.name;
                if (name == "Boat") {
                    action.SetOff();
                }
                if (name.StartsWith("Priest") || name.StartsWith("Devil")) {
                    action.Switch(hit.transform.gameObject);
                }
            }
        }
    }
    void OnGUI() {
        if (action.CheckGameState() == 0) {
            return;
        }
        string text = "";
        if (action.CheckGameState() == 1) {
            text = "Game Over";
        }
        else {
            text = "You Win";
        }
        float width = 100.0f;
        GUI.Label(new Rect((Screen.width - width) * 0.5f, 100.0f, width, 50.0f), text);
        if (GUI.Button(new Rect((Screen.width - width) * 0.5f, 130.0f, width, 50.0f), "RESTART")) {
            action.Init();
        }
    }
}
